package com.gidgabs.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.gidgabs.common.utils.PageUtils;
import com.gidgabs.common.utils.Query;
import com.gidgabs.common.utils.R;
import com.gidgabs.modules.api.service.TbOrderInfoService;
import com.gidgabs.modules.entity.TbOrderInfoEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品订单详细表
 *
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-07-06 18:14:03
 */
@RestController
@RequestMapping("/api/orderinfo")
public class TbOrderInfoController {
	@Autowired
	private TbOrderInfoService orderInfoService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("orderinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TbOrderInfoEntity> orderInfoList = orderInfoService.queryList(query);
		int total = orderInfoService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(orderInfoList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("orderinfo:info")
	public R info(@PathVariable("id") Integer id){
		TbOrderInfoEntity orderInfo = orderInfoService.queryObject(id);

		return R.ok().put("orderInfo", orderInfo);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("orderinfo:save")
	public R save(@RequestBody TbOrderInfoEntity orderInfo){
		orderInfoService.save(orderInfo);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("orderinfo:update")
	public R update(@RequestBody TbOrderInfoEntity orderInfo){
		orderInfoService.update(orderInfo);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("orderinfo:delete")
	public R delete(@RequestBody Integer[] ids){
		orderInfoService.deleteBatch(ids);

		return R.ok();
	}

}
